package com.tanhua.server.controller;

import com.tanhua.domain.db.PageResult;
import com.tanhua.domain.vo.MoreDataVo;
import com.tanhua.domain.vo.PublishVo;
import com.tanhua.server.service.PublishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@RestController
@RequestMapping("/movements")
@Slf4j
public class PublishController {

    @Autowired
    private PublishService publishService;

    /**
     * 发布动态
     * @param publishVo
     * @param imageContent
     * @return
     */
    @PostMapping
    public ResponseEntity publishData(PublishVo publishVo, MultipartFile[] imageContent) {
            //调用publishService方法 传入参数
        log.debug("来到了PublishController——————");
        publishService.publishData(publishVo,imageContent);
        //返回状态码
        return ResponseEntity.ok(null);
    }

    /**
     * 接受好友动态
     */
    @GetMapping
    public ResponseEntity friendData(Integer page,Integer pagesize) {
        //调用publishService
        PageResult<MoreDataVo> moreDataVoPageResult = publishService.friendData(page,pagesize);
        //返回状态码
        return ResponseEntity.ok(moreDataVoPageResult);
    }

    /**
     * 推荐随机动态
     */
    @GetMapping("/recommend")
    public ResponseEntity recommendData(Integer page,Integer pagesize) {
        //调用逻辑层 返回一个PageResult<MoreDataVo>
        PageResult<MoreDataVo> moreDataVoPageResult=publishService.recommendData(page,pagesize);
        //返回状态信息
        return ResponseEntity.ok(moreDataVoPageResult);
    }

    /**
     * 我的动态
     */
    @GetMapping("/all")
    public ResponseEntity MyPublishData(Integer page,Integer pagesize,Long userId) {
        //调用逻辑层 返回一个PageResult<MoreDataVo>
        PageResult<MoreDataVo> moreDataVoPageResult=publishService.MyPublishData(page,pagesize,userId);
        //返回状态信息
        return ResponseEntity.ok(moreDataVoPageResult);
    }


}
